package com.spring.cloud.practice.demo.springboot.shiro.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <b><code>LoginController</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 21-3-24 下午3:53.
 *
 * @author huanghuayan
 * @since spring-cloud-demo
 */
@RestController
@RequestMapping(value = "/v1.0")
public class LoginController {

    @PostMapping(value ="/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password) {
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        subject.login(token);

        return "true";
    }
}
